public class Solution {
    public int longestOnes(int[] nums, int k) {
        int ret = 0;
        for(int left = 0,right = 0,zero = 0;right<nums.length;right++){
            if(nums[right] == 0) zero++;//进窗口
            //判断
            while(zero > k){
                if (nums[left]==0) zero--;
                //出窗口
                left++;
            }
            //更新
            ret = Math.max(ret, right - left +1);
        }
        return ret;
    }
}
